package com.tedu.controller;

import com.tedu.service.FileService;
import com.tedu.vo.ImageVo;
import com.tedu.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * Author：毕龙
 * Date: 2022/9/22 15:01
 */
@RestController
@CrossOrigin
@RequestMapping("/file")
public class FileController {

    @Autowired
    private FileService fileService;

    /**
     * 需求分析：
     *      请求路径：http://localhost:8091/file/upload
     *      请求类型：post
     *      请求参数：file  二进制的字节信息
     *      返回值： SysResult
     *
     */
    @PostMapping("/upload")
    public SysResult upload(MultipartFile file){
        ImageVo imageVo = fileService.upload(file);
        if(imageVo == null){
            return SysResult.fail();
        }
        return SysResult.success();
    }

}
